#include <sys/types.h>
#include <unistd.h>
#include <signal.h>

#include <ptrace.h>
#include <devices.h>

int cpid;

/**
 * In answer to SIGINT (C-c)
 */
void
terminal (int sig_no)
{
	device_dtor ();
	kill (cpid, SIGKILL);
	_exit (0);
}


/**
 * The entry.
 * Fork a child as the main process and be the tracing one itself.
 */
int main (int argc, char* argv[], char* envp[])
{
	signal (SIGINT, terminal);
	
	device_init_common ();
	cpid = fork ();
	if (cpid == 0) {
		device_init_child_process ();
		ptraced_child ();
	} else {
		device_init_tracing_process (cpid);
		um_ptrace (cpid);
		device_dtor ();
	}

	return 0;
}

